package com.tzbank.back.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.tzbank.back.service.ServiceEvaluationService;
import com.tzbank.entity.backstage.ProductEvaluation;
import com.tzbank.entity.backstage.ServiceEvaluation;
import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.ResultUtil;

import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
/**
 * 服务评价配置
 * @author 蔡宇钿
 *2018年5月29日
 *更新 蔡宇钿 2018.6.1
 */
@Slf4j
@RestController
public class ServiceEvaluationController {
	
	@Autowired
	private ServiceEvaluationService serviceEvaluationSercice;
	
	@GetMapping(value = "getlistService")
	// 查询全部
//	public Map<String, Object> getlistServicelist(HttpServletRequest request) {
//		try {
//			return this.serviceEvaluationSercice.getlistService();
//		} catch (Exception e) {
//			log.error("ServiceEvaluationController getlistService: ", e);
//			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
//		}
//	}
//
//	@GetMapping(value = "getlistByevaluation")
	// 按照evaluation查询
	public Map<String, Object> getlistByevaluation(HttpServletRequest request, @RequestParam(required = false) String evaluation) {
		try {
			if (null == evaluation || evaluation.equals("")) {
				return this.serviceEvaluationSercice.getlistService();
			}else {
				return this.serviceEvaluationSercice.getlistByevaluation(evaluation);
			}
			
		} catch (Exception e) {
			log.error("ServiceEvaluationController getlistByevaluation: ", e);
			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
		}
	}

	@PostMapping(value = "addService")
	// 增加配置
	public Map<String, Object> addService(HttpServletRequest request,@RequestBody ServiceEvaluation cptcInfoJson) {
		try {
//			cptcInfoJson.put("operator", "userId");
			return this.serviceEvaluationSercice.addService(cptcInfoJson);
		} catch (Exception e) {
			log.error("ServiceEvaluationController addService: ", e);
			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
		}
	}

	@PostMapping(value = "modifyByserviceautoId")
	// 更新配置
	public Map<String, Object> modifyByserviceautoId(HttpServletRequest request, @RequestBody ServiceEvaluation cptcInfoJson) {
		try {
//			cptcInfoJson.put("operator", "userId");
			return this.serviceEvaluationSercice.modifyByserviceautoId(cptcInfoJson);
		} catch (Exception e) {
			log.error("ServiceEvaluationController modifyByserviceautoId n: ", e);
			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
		}
	}

	@PostMapping(value = "deleteByserviceautoId")
	// 通过逻辑方式实现删除
	public Map<String, Object> deleteByserviceautoId(HttpServletRequest request, @RequestBody ProductEvaluation cptcInfoJson) {
		try {
			return this.serviceEvaluationSercice.deleteByserviceautoId(cptcInfoJson);
		} catch (Exception e) {
			log.error("ServiceEvaluationController deleteByserviceautoId: ", e);
			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
		}
	}
}
